package com.net.web.server.strategy.impl;


import com.net.common.entity.Message;
import com.net.web.server.strategy.IMessageStrategy;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 消息上下文管理器
 *
 * @author hjh
 */
@Component
public class MessageContext {
    private final static Map<String, IMessageStrategy<Message>> SERVICES = new ConcurrentHashMap<>();

    public static IMessageStrategy<Message> getMessageStrategy(String messageType) {
        Assert.notNull(messageType, "messageType不能为空");
        return SERVICES.get(messageType);
    }

    public static void register(String messageType, IMessageStrategy<Message> iMessageStrategy) {
        Assert.notNull(messageType, "messageType不能为空");
        SERVICES.put(messageType, iMessageStrategy);
    }
}
